﻿using System;
using System.Collections.Generic;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x02000308 RID: 776
	public class HeadmanNeedsGrainIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x17000AFB RID: 2811
		// (get) Token: 0x06002D23 RID: 11555 RVA: 0x000BD088 File Offset: 0x000BB288
		private static int AverageGrainPriceInCalradia
		{
			get
			{
				return Campaign.Current.GetCampaignBehavior<HeadmanNeedsGrainIssueBehavior>()._averageGrainPriceInCalradia;
			}
		}

		// Token: 0x06002D24 RID: 11556 RVA: 0x000BD09C File Offset: 0x000BB29C
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
			CampaignEvents.WeeklyTickEvent.AddNonSerializedListener(this, new Action(this.WeeklyTick));
			CampaignEvents.OnGameLoadFinishedEvent.AddNonSerializedListener(this, new Action(this.OnGameLoadFinished));
			CampaignEvents.OnNewGameCreatedPartialFollowUpEvent.AddNonSerializedListener(this, new Action<CampaignGameStarter, int>(this.OnNewGameCreatedPartialFollowUp));
		}

		// Token: 0x06002D25 RID: 11557 RVA: 0x000BD105 File Offset: 0x000BB305
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x06002D26 RID: 11558 RVA: 0x000BD108 File Offset: 0x000BB308
		private bool ConditionsHold(Hero issueGiver)
		{
			return issueGiver.CurrentSettlement != null && issueGiver.IsNotable && issueGiver.CurrentSettlement.IsVillage && issueGiver.CurrentSettlement.Village.Bound.IsTown && (issueGiver.IsHeadman && issueGiver.CurrentSettlement.Village.VillageType == DefaultVillageTypes.WheatFarm) && (float)issueGiver.CurrentSettlement.Village.GetItemPrice(DefaultItems.Grain, null, false) > (float)this._averageGrainPriceInCalradia * 1.3f;
		}

		// Token: 0x06002D27 RID: 11559 RVA: 0x000BD194 File Offset: 0x000BB394
		public void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnSelected), typeof(HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssue), IssueBase.IssueFrequency.Rare, null));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssue), IssueBase.IssueFrequency.Rare));
		}

		// Token: 0x06002D28 RID: 11560 RVA: 0x000BD1F8 File Offset: 0x000BB3F8
		private IssueBase OnSelected(in PotentialIssueData pid, Hero issueOwner)
		{
			return new HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssue(issueOwner);
		}

		// Token: 0x06002D29 RID: 11561 RVA: 0x000BD200 File Offset: 0x000BB400
		private void WeeklyTick()
		{
			this.CacheGrainPrice();
		}

		// Token: 0x06002D2A RID: 11562 RVA: 0x000BD208 File Offset: 0x000BB408
		private void OnGameLoadFinished()
		{
			this.CacheGrainPrice();
		}

		// Token: 0x06002D2B RID: 11563 RVA: 0x000BD210 File Offset: 0x000BB410
		private void OnNewGameCreatedPartialFollowUp(CampaignGameStarter starter, int i)
		{
			if (i == 99)
			{
				this.CacheGrainPrice();
			}
		}

		// Token: 0x06002D2C RID: 11564 RVA: 0x000BD21D File Offset: 0x000BB41D
		private void CacheGrainPrice()
		{
			this._averageGrainPriceInCalradia = QuestHelper.GetAveragePriceOfItemInTheWorld(DefaultItems.Grain);
		}

		// Token: 0x04000D87 RID: 3463
		private const IssueBase.IssueFrequency HeadmanNeedsGrainIssueFrequency = IssueBase.IssueFrequency.Rare;

		// Token: 0x04000D88 RID: 3464
		private const int NearbyTownMarketGrainLimit = 100;

		// Token: 0x04000D89 RID: 3465
		private int _averageGrainPriceInCalradia;

		// Token: 0x0200062A RID: 1578
		public class HeadmanNeedsGrainIssue : IssueBase
		{
			// Token: 0x06004C65 RID: 19557 RVA: 0x0015F253 File Offset: 0x0015D453
			internal static void AutoGeneratedStaticCollectObjectsHeadmanNeedsGrainIssue(object o, List<object> collectedObjects)
			{
				((HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004C66 RID: 19558 RVA: 0x0015F261 File Offset: 0x0015D461
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x17000F7C RID: 3964
			// (get) Token: 0x06004C67 RID: 19559 RVA: 0x0015F26A File Offset: 0x0015D46A
			public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
			{
				get
				{
					return IssueBase.AlternativeSolutionScaleFlag.Duration;
				}
			}

			// Token: 0x17000F7D RID: 3965
			// (get) Token: 0x06004C68 RID: 19560 RVA: 0x0015F26D File Offset: 0x0015D46D
			private int NeededGrainAmount
			{
				get
				{
					return (int)(12f + 180f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000F7E RID: 3966
			// (get) Token: 0x06004C69 RID: 19561 RVA: 0x0015F282 File Offset: 0x0015D482
			private int AlternativeSolutionNeededGold
			{
				get
				{
					return this.NeededGrainAmount * HeadmanNeedsGrainIssueBehavior.AverageGrainPriceInCalradia;
				}
			}

			// Token: 0x17000F7F RID: 3967
			// (get) Token: 0x06004C6A RID: 19562 RVA: 0x0015F290 File Offset: 0x0015D490
			public override int AlternativeSolutionBaseNeededMenCount
			{
				get
				{
					return 3 + MathF.Ceiling(6f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000F80 RID: 3968
			// (get) Token: 0x06004C6B RID: 19563 RVA: 0x0015F2A5 File Offset: 0x0015D4A5
			protected override int AlternativeSolutionBaseDurationInDaysInternal
			{
				get
				{
					return 2 + MathF.Ceiling(6f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000F81 RID: 3969
			// (get) Token: 0x06004C6C RID: 19564 RVA: 0x0015F2BA File Offset: 0x0015D4BA
			protected override int RewardGold
			{
				get
				{
					return 0;
				}
			}

			// Token: 0x17000F82 RID: 3970
			// (get) Token: 0x06004C6D RID: 19565 RVA: 0x0015F2C0 File Offset: 0x0015D4C0
			[CachedData]
			private Settlement NearbySuitableSettlement
			{
				get
				{
					if (this._nearbySuitableSettlementCache == null)
					{
						Settlement nearbySuitableSettlementCache = SettlementHelper.FindNearestSettlement(delegate(Settlement x)
						{
							if (x.Town != null && !x.Town.IsCastle && !x.MapFaction.IsAtWarWith(base.IssueOwner.MapFaction))
							{
								int price = x.Town.MarketData.GetPrice(DefaultItems.Grain, MobileParty.MainParty, false, null);
								return price > 0 && price < HeadmanNeedsGrainIssueBehavior.AverageGrainPriceInCalradia * 2;
							}
							return false;
						}, null);
						this._nearbySuitableSettlementCache = nearbySuitableSettlementCache;
					}
					return this._nearbySuitableSettlementCache;
				}
			}

			// Token: 0x17000F83 RID: 3971
			// (get) Token: 0x06004C6E RID: 19566 RVA: 0x0015F2F5 File Offset: 0x0015D4F5
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=sQBBOKDD}{ISSUE_SETTLEMENT} Needs Grain Seeds", null);
					textObject.SetTextVariable("ISSUE_SETTLEMENT", base.IssueSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17000F84 RID: 3972
			// (get) Token: 0x06004C6F RID: 19567 RVA: 0x0015F319 File Offset: 0x0015D519
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=OJObD61e}The headman of {ISSUE_SETTLEMENT} needs grain seeds for the coming sowing season.", null);
					textObject.SetTextVariable("ISSUE_SETTLEMENT", base.IssueSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17000F85 RID: 3973
			// (get) Token: 0x06004C70 RID: 19568 RVA: 0x0015F33D File Offset: 0x0015D53D
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					return new TextObject("{=p1buAbOQ}The harvest has been poor, and rats have eaten much of our stores. We can eat less and tighten our belts, but if we don't have seed grain left over to plant, we'll starve next year.[if:convo_dismayed][ib:demure2]", null);
				}
			}

			// Token: 0x17000F86 RID: 3974
			// (get) Token: 0x06004C71 RID: 19569 RVA: 0x0015F34A File Offset: 0x0015D54A
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					return new TextObject("{=vKwndBbe}Is there a way to prevent this?", null);
				}
			}

			// Token: 0x17000F87 RID: 3975
			// (get) Token: 0x06004C72 RID: 19570 RVA: 0x0015F358 File Offset: 0x0015D558
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=nG750jQB}Grain will solve our problems. If we had {GRAIN_AMOUNT} bushels, we could use it to sow our fields. But I doubt that {NEARBY_TOWN} has so much to sell at this time of the year. {GRAIN_AMOUNT} bushels of grain costs around {DENAR_AMOUNT}{GOLD_ICON} in the markets, and we don't have that![if:convo_thinking]", null);
					int price = this.NearbySuitableSettlement.Town.MarketData.GetPrice(DefaultItems.Grain, MobileParty.MainParty, false, null);
					textObject.SetTextVariable("NEARBY_TOWN", this.NearbySuitableSettlement.Name);
					textObject.SetTextVariable("GRAIN_AMOUNT", this.NeededGrainAmount);
					textObject.SetTextVariable("DENAR_AMOUNT", price * this.NeededGrainAmount);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000F88 RID: 3976
			// (get) Token: 0x06004C73 RID: 19571 RVA: 0x0015F3E0 File Offset: 0x0015D5E0
			public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=5NYPqKBj}I know you're busy, but maybe you can ask some of your men to find us that grain? {MEN_COUNT} men should do the job along with {GOLD}{GOLD_ICON}, and I'd reckon the whole affair should take two weeks. \nI'm desperate here, {?PLAYER.GENDER}madam{?}sir{\\?}... Don't let our children starve![if:convo_dismayed][ib:demure]", null);
					textObject.SetTextVariable("MEN_COUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("GOLD", this.AlternativeSolutionNeededGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetCharacterProperties("PLAYER", Hero.MainHero.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x17000F89 RID: 3977
			// (get) Token: 0x06004C74 RID: 19572 RVA: 0x0015F443 File Offset: 0x0015D643
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					return new TextObject("{=ihfuqu2S}I will find that seed grain for you.", null);
				}
			}

			// Token: 0x17000F8A RID: 3978
			// (get) Token: 0x06004C75 RID: 19573 RVA: 0x0015F450 File Offset: 0x0015D650
			public override TextObject IssueAlternativeSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=HCMsvAFv}I can order one of my companions and {MEN_COUNT} men to find grain for you.", null);
					textObject.SetTextVariable("MEN_COUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					return textObject;
				}
			}

			// Token: 0x17000F8B RID: 3979
			// (get) Token: 0x06004C76 RID: 19574 RVA: 0x0015F46F File Offset: 0x0015D66F
			public override TextObject IssueDiscussAlternativeSolution
			{
				get
				{
					return new TextObject("{=W6X5DffB}Thank you for sparing the men to bring us that seed grain, {?PLAYER.GENDER}madam{?}sir{\\?}. That should get us through the hard times ahead.[if:convo_grateful][ib:normal]", null);
				}
			}

			// Token: 0x17000F8C RID: 3980
			// (get) Token: 0x06004C77 RID: 19575 RVA: 0x0015F47C File Offset: 0x0015D67C
			public override TextObject IssueAsRumorInSettlement
			{
				get
				{
					TextObject textObject = new TextObject("{=WVobv24n}Heaven save us if {QUEST_GIVER.NAME} can't get {?QUEST_GIVER.GENDER}her{?}his{\\?} hands on more grain.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000F8D RID: 3981
			// (get) Token: 0x06004C78 RID: 19576 RVA: 0x0015F4AE File Offset: 0x0015D6AE
			public override TextObject IssueAlternativeSolutionResponseByIssueGiver
			{
				get
				{
					return new TextObject("{=k63ZKmXX}Thank you, {?PLAYER.GENDER}milady{?}sir{\\?}! You are a saviour.[if:convo_grateful][ib:normal]", null);
				}
			}

			// Token: 0x17000F8E RID: 3982
			// (get) Token: 0x06004C79 RID: 19577 RVA: 0x0015F4BB File Offset: 0x0015D6BB
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return true;
				}
			}

			// Token: 0x17000F8F RID: 3983
			// (get) Token: 0x06004C7A RID: 19578 RVA: 0x0015F4BE File Offset: 0x0015D6BE
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000F90 RID: 3984
			// (get) Token: 0x06004C7B RID: 19579 RVA: 0x0015F4C4 File Offset: 0x0015D6C4
			protected override TextObject AlternativeSolutionStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=a0UTO8tW}{ISSUE_OWNER.LINK}, the headman of {ISSUE_SETTLEMENT}, asked you to deliver {GRAIN_AMOUNT} bushels of grain to {?QUEST_GIVER.GENDER}her{?}him{\\?} to use as seeds. Otherwise the peasants cannot sow their fields and starve in the coming season. You have agreed to send your companion {COMPANION.NAME} along with {MEN_COUNT} men to find some grain and return to the village. Your men should return in {RETURN_DAYS} days.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("ISSUE_SETTLEMENT", base.IssueSettlement.Name);
					textObject.SetTextVariable("GRAIN_AMOUNT", this.NeededGrainAmount);
					textObject.SetTextVariable("RETURN_DAYS", base.GetTotalAlternativeSolutionDurationInDays());
					textObject.SetTextVariable("MEN_COUNT", this.AlternativeSolutionSentTroops.TotalManCount - 1);
					return textObject;
				}
			}

			// Token: 0x17000F91 RID: 3985
			// (get) Token: 0x06004C7C RID: 19580 RVA: 0x0015F562 File Offset: 0x0015D762
			protected override int CompanionSkillRewardXP
			{
				get
				{
					return (int)(500f + 700f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x06004C7D RID: 19581 RVA: 0x0015F577 File Offset: 0x0015D777
			public HeadmanNeedsGrainIssue(Hero issueOwner) : base(issueOwner, CampaignTime.DaysFromNow(30f))
			{
			}

			// Token: 0x06004C7E RID: 19582 RVA: 0x0015F58A File Offset: 0x0015D78A
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.SettlementProsperity)
				{
					return -0.2f;
				}
				if (issueEffect == DefaultIssueEffects.SettlementLoyalty)
				{
					return -0.5f;
				}
				return 0f;
			}

			// Token: 0x06004C7F RID: 19583 RVA: 0x0015F5AD File Offset: 0x0015D7AD
			public override ValueTuple<SkillObject, int> GetAlternativeSolutionSkill(Hero hero)
			{
				return new ValueTuple<SkillObject, int>((hero.GetSkillValue(DefaultSkills.Trade) >= hero.GetSkillValue(DefaultSkills.Medicine)) ? DefaultSkills.Trade : DefaultSkills.Medicine, 120);
			}

			// Token: 0x06004C80 RID: 19584 RVA: 0x0015F5DA File Offset: 0x0015D7DA
			public override bool DoTroopsSatisfyAlternativeSolution(TroopRoster troopRoster, out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(troopRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 0, false);
			}

			// Token: 0x06004C81 RID: 19585 RVA: 0x0015F5F2 File Offset: 0x0015D7F2
			public override bool AlternativeSolutionCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(MobileParty.MainParty.MemberRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 0, false) && QuestHelper.CheckGoldForAlternativeSolution(this.AlternativeSolutionNeededGold, ref explanation);
			}

			// Token: 0x06004C82 RID: 19586 RVA: 0x0015F624 File Offset: 0x0015D824
			public override void AlternativeSolutionStartConsequence()
			{
				GiveGoldAction.ApplyForCharacterToParty(Hero.MainHero, base.IssueSettlement.Party, this.AlternativeSolutionNeededGold, false);
				TextObject textObject = new TextObject("{=ex6ZhAAv}You gave {DENAR}{GOLD_ICON} to companion to buy {GRAIN_AMOUNT} units of grain for the {ISSUE_OWNER.NAME}.", null);
				textObject.SetTextVariable("GRAIN_AMOUNT", this.NeededGrainAmount);
				textObject.SetTextVariable("DENAR", this.AlternativeSolutionNeededGold);
				textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
				StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
				MBInformationManager.AddQuickInformation(textObject, 0, null, "");
			}

			// Token: 0x06004C83 RID: 19587 RVA: 0x0015F6B4 File Offset: 0x0015D8B4
			protected override void AlternativeSolutionEndWithSuccessConsequence()
			{
				TraitLevelingHelper.OnIssueSolvedThroughAlternativeSolution(base.IssueOwner, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Generosity, 30)
				});
				base.IssueOwner.AddPower(10f);
				base.IssueSettlement.Village.Bound.Town.Prosperity += 50f;
				this.RelationshipChangeWithIssueOwner = 2;
				foreach (Hero hero in base.IssueOwner.CurrentSettlement.Notables)
				{
					if (hero != base.IssueOwner)
					{
						ChangeRelationAction.ApplyPlayerRelation(hero, 1, true, true);
					}
				}
			}

			// Token: 0x06004C84 RID: 19588 RVA: 0x0015F77C File Offset: 0x0015D97C
			protected override void AlternativeSolutionEndWithFailureConsequence()
			{
				base.IssueOwner.AddPower(-5f);
				foreach (Hero gainedRelationWith in base.IssueOwner.CurrentSettlement.Notables)
				{
					ChangeRelationAction.ApplyPlayerRelation(gainedRelationWith, -3, true, true);
				}
				base.IssueSettlement.Village.Bound.Town.Prosperity += -10f;
			}

			// Token: 0x06004C85 RID: 19589 RVA: 0x0015F810 File Offset: 0x0015DA10
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.Rare;
			}

			// Token: 0x06004C86 RID: 19590 RVA: 0x0015F813 File Offset: 0x0015DA13
			public override bool IssueStayAliveConditions()
			{
				return this.NearbySuitableSettlement != null && this.NearbySuitableSettlement.Town.MarketData.GetItemCountOfCategory(DefaultItems.Grain.ItemCategory) < 100;
			}

			// Token: 0x06004C87 RID: 19591 RVA: 0x0015F842 File Offset: 0x0015DA42
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x06004C88 RID: 19592 RVA: 0x0015F844 File Offset: 0x0015DA44
			protected override void OnGameLoad()
			{
			}

			// Token: 0x06004C89 RID: 19593 RVA: 0x0015F846 File Offset: 0x0015DA46
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004C8A RID: 19594 RVA: 0x0015F848 File Offset: 0x0015DA48
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssueQuest(questId, base.IssueOwner, CampaignTime.DaysFromNow(18f), base.IssueDifficultyMultiplier, this.RewardGold, this.NeededGrainAmount);
			}

			// Token: 0x06004C8B RID: 19595 RVA: 0x0015F874 File Offset: 0x0015DA74
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				skill = null;
				relationHero = null;
				flag = IssueBase.PreconditionFlags.None;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flag |= IssueBase.PreconditionFlags.Relation;
					relationHero = issueGiver;
				}
				if (FactionManager.IsAtWarAgainstFaction(issueGiver.CurrentSettlement.MapFaction, Hero.MainHero.MapFaction))
				{
					flag |= IssueBase.PreconditionFlags.AtWar;
				}
				return flag == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x040019C0 RID: 6592
			private const int IssueDuration = 30;

			// Token: 0x040019C1 RID: 6593
			private const int AlternativeSolutionSuccessGenerosityBonus = 30;

			// Token: 0x040019C2 RID: 6594
			private const int AlternativeSolutionFailPowerPenalty = -5;

			// Token: 0x040019C3 RID: 6595
			private const int QuestTimeLimit = 18;

			// Token: 0x040019C4 RID: 6596
			private const int AlternativeSolutionSuccessPowerBonus = 10;

			// Token: 0x040019C5 RID: 6597
			private const int AlternativeSolutionSuccessRelationBonusWithQuestGiver = 2;

			// Token: 0x040019C6 RID: 6598
			private const int AlternativeSolutionSuccessRelationBonusWithOtherNotables = 1;

			// Token: 0x040019C7 RID: 6599
			private const int AlternativeSolutionFailRelationPenaltyWithNotables = -3;

			// Token: 0x040019C8 RID: 6600
			private const int AlternativeSolutionSuccessProsperityBonus = 50;

			// Token: 0x040019C9 RID: 6601
			private const int AlternativeSolutionFailProsperityPenalty = -10;

			// Token: 0x040019CA RID: 6602
			private const int CompanionTradeSkillLimit = 120;

			// Token: 0x040019CB RID: 6603
			[CachedData]
			private Settlement _nearbySuitableSettlementCache;
		}

		// Token: 0x0200062B RID: 1579
		public class HeadmanNeedsGrainIssueQuest : QuestBase
		{
			// Token: 0x06004C8D RID: 19597 RVA: 0x0015F935 File Offset: 0x0015DB35
			internal static void AutoGeneratedStaticCollectObjectsHeadmanNeedsGrainIssueQuest(object o, List<object> collectedObjects)
			{
				((HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004C8E RID: 19598 RVA: 0x0015F943 File Offset: 0x0015DB43
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._playerAcceptedQuestLog);
				collectedObjects.Add(this._playerHasNeededGrainsLog);
			}

			// Token: 0x06004C8F RID: 19599 RVA: 0x0015F964 File Offset: 0x0015DB64
			internal static object AutoGeneratedGetMemberValue_neededGrainAmount(object o)
			{
				return ((HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssueQuest)o)._neededGrainAmount;
			}

			// Token: 0x06004C90 RID: 19600 RVA: 0x0015F976 File Offset: 0x0015DB76
			internal static object AutoGeneratedGetMemberValue_rewardGold(object o)
			{
				return ((HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssueQuest)o)._rewardGold;
			}

			// Token: 0x06004C91 RID: 19601 RVA: 0x0015F988 File Offset: 0x0015DB88
			internal static object AutoGeneratedGetMemberValue_playerAcceptedQuestLog(object o)
			{
				return ((HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssueQuest)o)._playerAcceptedQuestLog;
			}

			// Token: 0x06004C92 RID: 19602 RVA: 0x0015F995 File Offset: 0x0015DB95
			internal static object AutoGeneratedGetMemberValue_playerHasNeededGrainsLog(object o)
			{
				return ((HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssueQuest)o)._playerHasNeededGrainsLog;
			}

			// Token: 0x17000F92 RID: 3986
			// (get) Token: 0x06004C93 RID: 19603 RVA: 0x0015F9A2 File Offset: 0x0015DBA2
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=apr2dH0n}{ISSUE_SETTLEMENT} Needs Grain Seeds", null);
					textObject.SetTextVariable("ISSUE_SETTLEMENT", base.QuestGiver.CurrentSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17000F93 RID: 3987
			// (get) Token: 0x06004C94 RID: 19604 RVA: 0x0015F9CB File Offset: 0x0015DBCB
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000F94 RID: 3988
			// (get) Token: 0x06004C95 RID: 19605 RVA: 0x0015F9D0 File Offset: 0x0015DBD0
			private TextObject _playerAcceptedQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=5CokRxmL}{QUEST_GIVER.LINK}, the headman of the {QUEST_SETTLEMENT} asked you to deliver {GRAIN_AMOUNT} units of grain to {?QUEST_GIVER.GENDER}her{?}him{\\?} to use as seeds. Otherwise peasants cannot sow their fields and starve in the coming season. \n \n You have agreed to bring them {GRAIN_AMOUNT} units of grain as soon as possible.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_SETTLEMENT", base.QuestGiver.CurrentSettlement.Name);
					textObject.SetTextVariable("GRAIN_AMOUNT", this._neededGrainAmount);
					return textObject;
				}
			}

			// Token: 0x17000F95 RID: 3989
			// (get) Token: 0x06004C96 RID: 19606 RVA: 0x0015FA30 File Offset: 0x0015DC30
			private TextObject _playerHasNeededGrainsLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=vOHc5dxC}You now have enough grain seeds to complete the quest. Return to {QUEST_SETTLEMENT} to hand them over.", null);
					textObject.SetTextVariable("QUEST_SETTLEMENT", base.QuestGiver.CurrentSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17000F96 RID: 3990
			// (get) Token: 0x06004C97 RID: 19607 RVA: 0x0015FA59 File Offset: 0x0015DC59
			private TextObject _questTimeoutLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=brDw7ewN}You have failed to deliver {GRAIN_AMOUNT} units of grain to the villagers. They won't be able to sow them before the coming winter. The Headman and the villagers are doomed.", null);
					textObject.SetTextVariable("GRAIN_AMOUNT", this._neededGrainAmount);
					return textObject;
				}
			}

			// Token: 0x17000F97 RID: 3991
			// (get) Token: 0x06004C98 RID: 19608 RVA: 0x0015FA78 File Offset: 0x0015DC78
			private TextObject _successLog
			{
				get
				{
					TextObject textObject = new TextObject("{=GGTxzAtn}You have delivered {GRAIN_AMOUNT} units of grain to the villagers. They will be able to sow them before the coming winter. You have saved a lot of lives today. The Headman and the villagers are grateful.", null);
					textObject.SetTextVariable("GRAIN_AMOUNT", this._neededGrainAmount);
					return textObject;
				}
			}

			// Token: 0x17000F98 RID: 3992
			// (get) Token: 0x06004C99 RID: 19609 RVA: 0x0015FA98 File Offset: 0x0015DC98
			private TextObject _cancelLogOnWarDeclared
			{
				get
				{
					TextObject textObject = new TextObject("{=8Z4vlcib}Your clan is now at war with the {ISSUE_GIVER.LINK}'s lord. Your agreement with {ISSUE_GIVER.LINK} was canceled.", null);
					StringHelpers.SetCharacterProperties("ISSUE_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000F99 RID: 3993
			// (get) Token: 0x06004C9A RID: 19610 RVA: 0x0015FACA File Offset: 0x0015DCCA
			private TextObject _failLogOnWarDeclaredByCriminalRating
			{
				get
				{
					TextObject textObject = new TextObject("{=BTp7qpak}You are accused of a crime, and {QUEST_GIVER.LINK} no longer wants your help.", null);
					textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x17000F9A RID: 3994
			// (get) Token: 0x06004C9B RID: 19611 RVA: 0x0015FAF0 File Offset: 0x0015DCF0
			private TextObject _playerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000F9B RID: 3995
			// (get) Token: 0x06004C9C RID: 19612 RVA: 0x0015FB24 File Offset: 0x0015DD24
			private TextObject _cancelLogOnVillageRaided
			{
				get
				{
					TextObject textObject = new TextObject("{=PgFJLK85}{SETTLEMENT_NAME} is raided. It isn’t safe for the villagers to plant their fields, and agreement with {ISSUE_GIVER.LINK} was canceled.", null);
					textObject.SetTextVariable("SETTLEMENT_NAME", base.QuestGiver.CurrentSettlement.Name);
					StringHelpers.SetCharacterProperties("ISSUE_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x06004C9D RID: 19613 RVA: 0x0015FB72 File Offset: 0x0015DD72
			public HeadmanNeedsGrainIssueQuest(string questId, Hero giverHero, CampaignTime duration, float difficultyMultiplier, int rewardGold, int neededGrainAmount) : base(questId, giverHero, duration, rewardGold)
			{
				this._neededGrainAmount = neededGrainAmount;
				this._rewardGold = rewardGold;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06004C9E RID: 19614 RVA: 0x0015FB9B File Offset: 0x0015DD9B
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
			}

			// Token: 0x06004C9F RID: 19615 RVA: 0x0015FBA3 File Offset: 0x0015DDA3
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004CA0 RID: 19616 RVA: 0x0015FBA8 File Offset: 0x0015DDA8
			protected override void RegisterEvents()
			{
				CampaignEvents.PlayerInventoryExchangeEvent.AddNonSerializedListener(this, new Action<List<ValueTuple<ItemRosterElement, int>>, List<ValueTuple<ItemRosterElement, int>>, bool>(this.OnPlayerInventoryExchange));
				CampaignEvents.OnPartyConsumedFoodEvent.AddNonSerializedListener(this, new Action<MobileParty>(this.OnPartyConsumedFood));
				CampaignEvents.OnHeroSharedFoodWithAnotherHeroEvent.AddNonSerializedListener(this, new Action<Hero, Hero, float>(this.OnHeroSharedFoodWithAnotherHero));
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
				CampaignEvents.HourlyTickPartyEvent.AddNonSerializedListener(this, new Action<MobileParty>(this.HourlyTickParty));
				CampaignEvents.HeroPrisonerTaken.AddNonSerializedListener(this, new Action<PartyBase, Hero>(this.OnHeroPrisonerTaken));
				CampaignEvents.SettlementEntered.AddNonSerializedListener(this, new Action<MobileParty, Settlement, Hero>(this.OnSettlementEntered));
				CampaignEvents.VillageBeingRaided.AddNonSerializedListener(this, new Action<Village>(this.OnVillageBeingRaided));
			}

			// Token: 0x06004CA1 RID: 19617 RVA: 0x0015FC9B File Offset: 0x0015DE9B
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
					return;
				}
				if (mapEvent.IsRaid || mapEvent.IsForcingSupplies || mapEvent.IsForcingVolunteers)
				{
					base.CompleteQuestWithCancel(this._cancelLogOnVillageRaided);
				}
			}

			// Token: 0x06004CA2 RID: 19618 RVA: 0x0015FCD3 File Offset: 0x0015DED3
			private void HourlyTickParty(MobileParty mobileParty)
			{
				if (mobileParty == MobileParty.MainParty)
				{
					this._playerAcceptedQuestLog.UpdateCurrentProgress(this.GetRequiredGrainCountOnPlayer());
					this.CheckIfPlayerReadyToReturnGrains();
				}
			}

			// Token: 0x06004CA3 RID: 19619 RVA: 0x0015FCF4 File Offset: 0x0015DEF4
			private void OnHeroPrisonerTaken(PartyBase capturer, Hero prisoner)
			{
				if (prisoner == Hero.MainHero)
				{
					this._playerAcceptedQuestLog.UpdateCurrentProgress(this.GetRequiredGrainCountOnPlayer());
					this.CheckIfPlayerReadyToReturnGrains();
				}
			}

			// Token: 0x06004CA4 RID: 19620 RVA: 0x0015FD15 File Offset: 0x0015DF15
			private void OnSettlementEntered(MobileParty party, Settlement settlement, Hero hero)
			{
				if (party == MobileParty.MainParty)
				{
					this._playerAcceptedQuestLog.UpdateCurrentProgress(this.GetRequiredGrainCountOnPlayer());
					this.CheckIfPlayerReadyToReturnGrains();
				}
			}

			// Token: 0x06004CA5 RID: 19621 RVA: 0x0015FD36 File Offset: 0x0015DF36
			private void OnVillageBeingRaided(Village village)
			{
				if (village == base.QuestGiver.CurrentSettlement.Village)
				{
					base.CompleteQuestWithCancel(this._cancelLogOnVillageRaided);
				}
			}

			// Token: 0x06004CA6 RID: 19622 RVA: 0x0015FD57 File Offset: 0x0015DF57
			protected override void OnTimedOut()
			{
				base.AddLog(this._questTimeoutLogText, false);
				this.TimeoutFail();
			}

			// Token: 0x06004CA7 RID: 19623 RVA: 0x0015FD70 File Offset: 0x0015DF70
			protected override void SetDialogs()
			{
				TextObject textObject = new TextObject("{=nwIYsJRO}Have you brought our grain {?PLAYER.GENDER}milady{?}sir{\\?}?[if:convo_shocked][ib:demure2]", null);
				TextObject textObject2 = new TextObject("{=zsE7ldPY}Thank you, {?PLAYER.GENDER}milady{?}sir{\\?}! You are a saviour.[if:convo_merry][ib:normal2]", null);
				TextObject textObject3 = new TextObject("{=0tB3VGE4}We await your success, {?PLAYER.GENDER}milady{?}sir{\\?}.[if:convo_nervous]", null);
				textObject.SetCharacterProperties("PLAYER", Hero.MainHero.CharacterObject, false);
				textObject2.SetCharacterProperties("PLAYER", Hero.MainHero.CharacterObject, false);
				textObject3.SetCharacterProperties("PLAYER", Hero.MainHero.CharacterObject, false);
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(textObject2, null, null).Condition(() => CharacterObject.OneToOneConversationCharacter == base.QuestGiver.CharacterObject).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(textObject, null, null).Condition(delegate
				{
					MBTextManager.SetTextVariable("GRAIN_AMOUNT", this._neededGrainAmount);
					return CharacterObject.OneToOneConversationCharacter == base.QuestGiver.CharacterObject;
				}).BeginPlayerOptions().PlayerOption(new TextObject("{=9UABeRWO}Yes. Here is your grain.", null), null).ClickableCondition(new ConversationSentence.OnClickableConditionDelegate(this.CompleteQuestClickableConditions)).NpcLine(textObject2, null, null).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += this.Success;
				}).CloseDialog().PlayerOption(new TextObject("{=PI6ikMsc}I'm working on it.", null), null).NpcLine(textObject3, null, null).CloseDialog().EndPlayerOptions().CloseDialog();
			}

			// Token: 0x06004CA8 RID: 19624 RVA: 0x0015FEBC File Offset: 0x0015E0BC
			private bool CompleteQuestClickableConditions(out TextObject explanation)
			{
				if (this._playerAcceptedQuestLog.CurrentProgress >= this._neededGrainAmount)
				{
					explanation = TextObject.Empty;
					return true;
				}
				explanation = new TextObject("{=mzabdwoh}You don't have enough grain.", null);
				return false;
			}

			// Token: 0x06004CA9 RID: 19625 RVA: 0x0015FEE8 File Offset: 0x0015E0E8
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				int requiredGrainCountOnPlayer = this.GetRequiredGrainCountOnPlayer();
				this._playerAcceptedQuestLog = base.AddDiscreteLog(this._playerAcceptedQuestLogText, new TextObject("{=eEwI880g}Collect Grain", null), requiredGrainCountOnPlayer, this._neededGrainAmount, null, false);
			}

			// Token: 0x06004CAA RID: 19626 RVA: 0x0015FF28 File Offset: 0x0015E128
			private int GetRequiredGrainCountOnPlayer()
			{
				int itemNumber = PartyBase.MainParty.ItemRoster.GetItemNumber(DefaultItems.Grain);
				if (itemNumber >= this._neededGrainAmount)
				{
					TextObject textObject = new TextObject("{=Gtbfm10o}You have enough grain to complete the quest. Return to {QUEST_SETTLEMENT} to hand it over.", null);
					textObject.SetTextVariable("QUEST_SETTLEMENT", base.QuestGiver.CurrentSettlement.Name);
					MBInformationManager.AddQuickInformation(textObject, 0, null, "");
				}
				if (itemNumber <= this._neededGrainAmount)
				{
					return itemNumber;
				}
				return this._neededGrainAmount;
			}

			// Token: 0x06004CAB RID: 19627 RVA: 0x0015FF98 File Offset: 0x0015E198
			private void CheckIfPlayerReadyToReturnGrains()
			{
				if (this._playerHasNeededGrainsLog == null && this._playerAcceptedQuestLog.CurrentProgress >= this._neededGrainAmount)
				{
					this._playerHasNeededGrainsLog = base.AddLog(this._playerHasNeededGrainsLogText, false);
					return;
				}
				if (this._playerHasNeededGrainsLog != null && this._playerAcceptedQuestLog.CurrentProgress < this._neededGrainAmount)
				{
					base.RemoveLog(this._playerHasNeededGrainsLog);
					this._playerHasNeededGrainsLog = null;
				}
			}

			// Token: 0x06004CAC RID: 19628 RVA: 0x00160004 File Offset: 0x0015E204
			private void OnPlayerInventoryExchange(List<ValueTuple<ItemRosterElement, int>> purchasedItems, List<ValueTuple<ItemRosterElement, int>> soldItems, bool isTrading)
			{
				bool flag = false;
				foreach (ValueTuple<ItemRosterElement, int> valueTuple in purchasedItems)
				{
					ItemRosterElement item = valueTuple.Item1;
					if (item.EquipmentElement.Item == DefaultItems.Grain)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					foreach (ValueTuple<ItemRosterElement, int> valueTuple2 in soldItems)
					{
						ItemRosterElement item = valueTuple2.Item1;
						if (item.EquipmentElement.Item == DefaultItems.Grain)
						{
							flag = true;
							break;
						}
					}
				}
				if (flag)
				{
					this._playerAcceptedQuestLog.UpdateCurrentProgress(this.GetRequiredGrainCountOnPlayer());
					this.CheckIfPlayerReadyToReturnGrains();
				}
			}

			// Token: 0x06004CAD RID: 19629 RVA: 0x001600E8 File Offset: 0x0015E2E8
			private void OnPartyConsumedFood(MobileParty party)
			{
				if (party.IsMainParty)
				{
					this._playerAcceptedQuestLog.UpdateCurrentProgress(this.GetRequiredGrainCountOnPlayer());
					this.CheckIfPlayerReadyToReturnGrains();
				}
			}

			// Token: 0x06004CAE RID: 19630 RVA: 0x00160109 File Offset: 0x0015E309
			private void OnHeroSharedFoodWithAnotherHero(Hero supporterHero, Hero supportedHero, float influence)
			{
				if (supporterHero == Hero.MainHero || supportedHero == Hero.MainHero)
				{
					this._playerAcceptedQuestLog.UpdateCurrentProgress(this.GetRequiredGrainCountOnPlayer());
					this.CheckIfPlayerReadyToReturnGrains();
				}
			}

			// Token: 0x06004CAF RID: 19631 RVA: 0x00160132 File Offset: 0x0015E332
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (base.QuestGiver.CurrentSettlement.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					base.CompleteQuestWithCancel(this._cancelLogOnWarDeclared);
				}
			}

			// Token: 0x06004CB0 RID: 19632 RVA: 0x00160161 File Offset: 0x0015E361
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				if (detail == DeclareWarAction.DeclareWarDetail.CausedByCrimeRatingChange)
				{
					if (base.QuestGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
					{
						this.CriminalRatingFail();
						return;
					}
				}
				else
				{
					QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this._playerDeclaredWarQuestLogText, this._cancelLogOnWarDeclared, true);
				}
			}

			// Token: 0x06004CB1 RID: 19633 RVA: 0x001601A0 File Offset: 0x0015E3A0
			private void Success()
			{
				base.AddLog(this._successLog, false);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(base.QuestGiver, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Mercy, 70),
					new Tuple<TraitObject, int>(DefaultTraits.Generosity, 50)
				});
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this._rewardGold, false);
				ItemRosterElement itemRosterElement = new ItemRosterElement(DefaultItems.Grain, this._neededGrainAmount, null);
				GiveItemAction.ApplyForParties(PartyBase.MainParty, Settlement.CurrentSettlement.Party, itemRosterElement);
				base.QuestGiver.AddPower(10f);
				base.QuestGiver.CurrentSettlement.Village.Bound.Town.Prosperity += 50f;
				this.RelationshipChangeWithQuestGiver = 2;
				foreach (Hero hero in base.QuestGiver.CurrentSettlement.Notables)
				{
					if (hero != base.QuestGiver)
					{
						ChangeRelationAction.ApplyPlayerRelation(hero, 1, true, true);
					}
				}
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x06004CB2 RID: 19634 RVA: 0x001602C8 File Offset: 0x0015E4C8
			private void TimeoutFail()
			{
				base.QuestGiver.AddPower(-5f);
				base.QuestGiver.CurrentSettlement.Village.Bound.Town.Prosperity += -10f;
				this.RelationshipChangeWithQuestGiver = -5;
				foreach (Hero hero in base.QuestGiver.CurrentSettlement.Notables)
				{
					if (hero != base.QuestGiver)
					{
						ChangeRelationAction.ApplyPlayerRelation(hero, -3, true, true);
					}
				}
			}

			// Token: 0x06004CB3 RID: 19635 RVA: 0x00160374 File Offset: 0x0015E574
			private void CriminalRatingFail()
			{
				base.QuestGiver.AddPower(-10f);
				this.RelationshipChangeWithQuestGiver = -5;
				TraitLevelingHelper.OnIssueFailed(Hero.MainHero, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -50)
				});
				base.CompleteQuestWithFail(this._failLogOnWarDeclaredByCriminalRating);
			}

			// Token: 0x040019CC RID: 6604
			private const int SuccessMercyBonus = 70;

			// Token: 0x040019CD RID: 6605
			private const int SuccessGenerosityBonus = 50;

			// Token: 0x040019CE RID: 6606
			private const int SuccessRelationBonusWithQuestGiver = 2;

			// Token: 0x040019CF RID: 6607
			private const int SuccessRelationBonusWithOtherNotables = 1;

			// Token: 0x040019D0 RID: 6608
			private const int SuccessPowerBonus = 10;

			// Token: 0x040019D1 RID: 6609
			private const int SuccessProsperityBonus = 50;

			// Token: 0x040019D2 RID: 6610
			private const int FailRelationPenalty = -5;

			// Token: 0x040019D3 RID: 6611
			private const int FailRelationPenaltyWithOtherNotables = -3;

			// Token: 0x040019D4 RID: 6612
			private const int CrimeRatingFailHonorPenalty = -50;

			// Token: 0x040019D5 RID: 6613
			private const int CrimeRatingFailRelationshipWithQuestGiverPenalty = -5;

			// Token: 0x040019D6 RID: 6614
			private const int CrimeRatingFailQuestGiverPowerPenalty = -10;

			// Token: 0x040019D7 RID: 6615
			private const int TimeOutProsperityPenalty = -10;

			// Token: 0x040019D8 RID: 6616
			private const int TimeOutPowerPenalty = -5;

			// Token: 0x040019D9 RID: 6617
			[SaveableField(10)]
			private readonly int _neededGrainAmount;

			// Token: 0x040019DA RID: 6618
			[SaveableField(20)]
			private int _rewardGold;

			// Token: 0x040019DB RID: 6619
			[SaveableField(30)]
			private JournalLog _playerAcceptedQuestLog;

			// Token: 0x040019DC RID: 6620
			[SaveableField(40)]
			private JournalLog _playerHasNeededGrainsLog;
		}

		// Token: 0x0200062C RID: 1580
		public class HeadmanNeedsGrainIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06004CB7 RID: 19639 RVA: 0x00160419 File Offset: 0x0015E619
			public HeadmanNeedsGrainIssueTypeDefiner() : base(440000)
			{
			}

			// Token: 0x06004CB8 RID: 19640 RVA: 0x00160426 File Offset: 0x0015E626
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssue), 1, null);
				base.AddClassDefinition(typeof(HeadmanNeedsGrainIssueBehavior.HeadmanNeedsGrainIssueQuest), 2, null);
			}
		}
	}
}
